package com.lvbaoins.creditapp.util;


import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * 
* @ClassName: StringUtils.java
* @Description: 字符串工具类
*
* @version: v1.0.0
* @author: liwei
* @date: 2019年6月14日 上午10:12:27 
*
 */
public class BeStringUtils {

	private static String str_62="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	
	private static String str_31="abcdefghjkmnpqrstuvwxyz23456789";
	
	private static String str_num="0123456789";
	
	public static String listToString(List<String> list) {
		return listToString(list,',');
	}
	
	public static String listToString(List<String> list, char separator) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < list.size(); i++) {
            sb.append(list.get(i)).append(separator);
        }
        return sb.toString().substring(0, sb.toString().length() - 1);
    }
	
	public static String collectionToString(String[] strs) {
		return collectionToString(strs,',');
	}
	
	public static String collectionToString(String[] strs, char separator) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < strs.length; i++) {
            sb.append(strs[i]).append(separator);
        }
        return sb.toString().substring(0, sb.toString().length() - 1);
    }
	
	public static String getRandomString31(int length){
	     Random random=new Random();
	     StringBuffer sb=new StringBuffer();
	     for(int i=0;i<length;i++){
	       int number=random.nextInt(31);
	       sb.append(str_31.charAt(number));
	     }
	     return sb.toString();
	 }
	
	public static String getRandomNumber(int length){
	     Random random=new Random();
	     StringBuffer sb=new StringBuffer();
	     for(int i=0;i<length;i++){
	       int number=random.nextInt(10);
	       sb.append(str_num.charAt(number));
	     }
	     return sb.toString();
	 }

	/**
	 * 生成用户code
	 * @return
	 */
	public static String generateUserCode(String type){
		 return type + BeStringUtils.getRandomString31(5).toUpperCase();
	 }

	public static String generateChannelCode(){
		return BeStringUtils.getRandomString31(5).toUpperCase();
	}

	public static String generateOrderNo(String prefix){
		if(StringUtils.isBlank(prefix) ) {
			prefix = "LB";
		}
		return prefix+DateUtils.dateToString(new Date(), "yyyyMMdd")+BeStringUtils.getRandomString31(4).toUpperCase();
	}

	public static String generateSimpleCode(){
		return BeStringUtils.getRandomString31(8).toUpperCase();
	}

	public static void main(String[] args) {
		System.out.println(("bel"+DateUtils.dateToString(new Date(), "yyyyMMdd")+BeStringUtils.getRandomString31(4)).toUpperCase());
	}
}
